import { Scene } from '@babylonjs/core/scene';
import { AbstractBase, IAbstractBaseOptions } from './abstract-base';
import { AbstractGroup, IAbstractGroupOptions } from './abstract-group';


/**
 * ui组控件参数对象
 * @param items 成员控件
 */
interface IUIGroupOptions extends IAbstractGroupOptions<IAbstractBaseOptions> {
    items?: Array<AbstractBase>,
}


/**
 * ui组控件
 * @param name 名称
 * @param scene 所在场景
 * @param options 参数对象
 */
class UIGroup extends AbstractGroup {

    constructor(name: string, scene: Scene, options?: IUIGroupOptions) {
        super(name, scene, options);
    }

    protected generateItem(name: string, scene: Scene, itemOptions: IAbstractBaseOptions, groupOptions: IUIGroupOptions): null {
        return null;
    }

    protected initializeItems(name: string, scene: Scene, itemsOptions: IAbstractBaseOptions[], groupOptions: IUIGroupOptions): AbstractBase[] {
        const items = groupOptions.items || [];
        items.forEach(item => item.container.parent = this.container);
        return items;
    }

}


/**
 * 创建ui组控件
 * @param name 名称
 * @param scene 所在场景
 * @param options 参数对象
 * @param items 成员控件
 * @returns ui组控件
 */
const CreateUIGroup = (name: string, scene: Scene, options?: IUIGroupOptions, items?: AbstractBase[]): UIGroup => {
    const ops: IUIGroupOptions = options || {};
    ops.items = ops.items || [];
    ops.items.push(...(items || []));
    const group = new UIGroup(name, scene, ops);
    return group;
};


export { UIGroup, CreateUIGroup };
export type { IUIGroupOptions };